package com.laima.basic.controller;

import com.laima.basic.Exception.Response;
import com.laima.basic.model.SysLogininfor;
import com.laima.basic.model.SysNotice;
import com.laima.basic.service.SysLogininforService;
import com.laima.basic.utils.poi.ExcelUtil;
import com.laima.basic.vo.SysLogininforVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.List;

/**
 * @program: backend-server
 * @description: 系统登陆日志
 * @author: T
 * @create: 2021-03-25 13:53
 **/

@Api(tags = {"登陆日志管理"})
@RestController
@RequestMapping("logininfor")
public class SysLogininforController {

    private Logger logger = LoggerFactory.getLogger(SysNoticeController.class);

    @Autowired
    private SysLogininforService sysLogininforService;

    @ApiOperation(value = "selectLogininforList", notes = "查看列表登录日志管理 ")
    @RequestMapping(value = "selectLogininforList", method = RequestMethod.POST)
    public Response selectLogininforList() {
        List<SysLogininforVo> list = sysLogininforService.selectLogininforList();
        return Response.ok(list);
    }


    @ApiOperation(value = "exportLogininfor", notes = "导出日志管理 ")
    @RequestMapping(value = "exportLogininfor", method = RequestMethod.POST)
    public Response exportLogininfor() throws FileNotFoundException {
        //查询
        List<SysLogininforVo> list = sysLogininforService.selectLogininforList();
        //调用导出方法
        ExcelUtil<SysLogininforVo> util = new ExcelUtil<>(SysLogininforVo.class);
        FileOutputStream out = new FileOutputStream("E:\\test.xls");
        util.getListToExcel(list, "test信息", out);
        return Response.ok("");
    }


    @ApiOperation(value = "insertLogininfor", notes = "新增登录日志管理 ")
    @RequestMapping(value = "insertLogininfor", method = RequestMethod.POST)
    public Response selectNoticeList(@RequestBody SysLogininfor sysLogininfor) {
        sysLogininforService.insertLogininfor(sysLogininfor);
        return Response.ok("");
    }


    @ApiOperation(value = "deleteLogininforByIds", notes = "批量删除列表登录日志管理 ")
    @RequestMapping(value = "deleteLogininforByIds", method = RequestMethod.GET)
    public Response deleteLogininforByIds(@PathVariable Long[] infoIds) {
        return Response.ok(sysLogininforService.deleteLogininforByIds(infoIds));
    }

    @ApiOperation(value = "cleanLogininfor", notes = "清空登录日志管理 ")
    @RequestMapping(value = "cleanLogininfor", method = RequestMethod.POST)
    public Response cleanLogininfor() {
        sysLogininforService.cleanLogininfor();
        return Response.ok("");
    }
}
